﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace UDPTest
{
    public partial class Form1 : Form
    {
        UdpClient udp = new UdpClient( new IPEndPoint(IPAddress.Any, 0));
        //Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        //IPEndPoint ipLocalPoint;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //ipLocalPoint = new IPEndPoint(IPAddress.Parse("192.168.1.6"),6543);
            //mySocket.Bind(ipLocalPoint);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 5000);
            string sendCmd = "<00:00:00:00:00:00>,<14:18:77:D4:F5:AA>,AT\r\n";
            byte[] sendByte = Encoding.Default.GetBytes(sendCmd);
            udp.Send(sendByte, sendByte.Length, ipe);

            IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 0);
            byte[] recData = udp.Receive(ref endpoint);
            string str = Encoding.Default.GetString(recData);
            listBox1.Items.Add(str);
        }
    }
}
